<template>
  <page-meta :page-style="$theme.pageStyle">
    <!-- #ifndef H5 -->
    <navigation-bar :front-color="$theme.navColor" :background-color="$theme.navBgColor" />
    <!-- #endif -->
  </page-meta>
  <view class="index" :style="$theme.pageStyle">
    <page-bg></page-bg>

    <!--顶部-->
    <u-navbar :safeAreaInsetTop="false" :placeholder="false" :is-back="true" :is-fixed="true" :title="'我的牵线'"
      :border-bottom="false" :title-bold="true" :title-color="'#111111'" :background="{ background: navBg }">
    </u-navbar>

    <view class="page-card">
      <view class="card-user">
        <view class="user-left">
          <image class="left-pic" mode="aspectFit" :src="theUserInfo.avatar"></image>
          <view class="left-data">
            <view class="data-title">
              您的牵线剩余次数
            </view>
            <view class="data-time">
              牵线次数越多机会也就越多～
            </view>
          </view>
        </view>
        <view class="user-right">
          <view class="right-number">
            {{ theUserInfo.qx_count }}
          </view>
          <view class="right-text">
            次
          </view>
        </view>
      </view>
      <view class="card-bottom">
        <view class="bottom-btn" @click="navTo('/packages/pages/user/vip')">
          <view class="btn-title">
            <view class="title-text">
              开通VIP会员
            </view>
            <u-image class="xbImg" :src="`../../../static/new/openVip.png`" width="68rpx" height="68rpx"></u-image>
          </view>
          <view class="btn-tip">
            获赠牵线次数
          </view>
        </view>
        <view class="bottom-btn" @click="navTo('/packagesA/pages/pullTheWirePackage/pullTheWirePackage')">
          <view class="btn-title">
            <view class="title-text">
              牵线服务套餐
            </view>
            <u-image class="xbImg" :src="`../../../static/new/qxtc.png`" width="68rpx" height="68rpx"></u-image>
          </view>
          <view class="btn-tip">
            单独购买更享优惠
          </view>
        </view>
      </view>
    </view>

    <view class="px-[30rpx] mt-3">
      <tabs :current="navCurrent" @change="navChange" bar-width="60" :isScroll="false" :activeColor="'#111'"
        :bgColor="'transparent'" :stickyBgColor="'transparent'" :fontSize="36" :bold="true" :inactiveColor="'#888'"
        :barStyle="{
          bottom: '-8rpx',
          height: '8rpx',
          borderRadius: '8rpx',
          backgroundColor: 'transparent',
          backgroundImage: 'linear-gradient(to right, #FFB9FA, #FF4DCA)'
        }">
        <tab v-for="(item, i) in navList" :key="i" :name="item.name"></tab>
      </tabs>
      <view class="mt-3">
        <view class="page-list">
          <view class="list-child" v-for="(item, index) in MyCollectBranch.lists" :key="index">
            <view class="child-item">
              <view class="item-time">
                申请时间：{{ item.update_time }}
              </view>
              <view class="item-box">
                <view class="box-user"
                  @click="navTo('/packagesA/pages/guestDetail/guestDetail?id=' + item.dara_user_info.id)">
                  <image class="user-pic" mode="aspectFit" :src="item.dara_user_info.avatar"></image>
                  <view class="user-data">
                    <view class="data-name">
                      <view class="name-text">{{ item.dara_user_info.nickname }}</view>
                      <view class="name-sex" v-if="item.dara_user_info.sex == '男'">
                        <u-icon class="sex-icon" size="22rpx" color="#fff" name="man"></u-icon>
                      </view>
                      <view class="name-sex top-sexNv" v-if="item.dara_user_info.sex == '女'">
                        <u-icon class="sex-icon" size="22rpx" color="#fff" name="woman"></u-icon>
                      </view>
                    </view>
                    <view class="data-id">
                      ID：{{ item.dara_user_info.sn }}
                    </view>
                  </view>
                  <view class="user-btn">
                    {{ setStatus(item.status) }}
                  </view>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>

  </view>
</template>

<script setup lang="ts">
import { computed, reactive, ref } from 'vue'
import { onLoad, onPageScroll, onReachBottom, onShow } from "@dcloudio/uni-app";
import {
  getDisInfoApi,
  getUserInfoApi,
  getMyCollectBranchListApi,
  getInviteUserListApi,
  getMyQxListApi
} from "@/api/new";


const titleColor = ref<string>('#fff')
const navBg = ref<string>('rgba(255,255,255,0)')

const setStatus = (status: any) => {
  switch (status) {
    case 1:
      return '牵线申请中'
    case 2:
      return '牵线失败'
    case 3:
      return '牵线成功'
    default:
      return '牵线申请中'
  }

}

onPageScroll((event: any) => {
  navBg.value = event.scrollTop > 10 ? '#fff' : 'rgba(255,255,255,0)'
  titleColor.value = event.scrollTop > 10 ? '#111' : '#fff'
})


const navChange = (item: any) => {
  navCurrent.value = item
  MyCollectBranch.value.lists = []
  formData.value = {
    page_no: 1,
    page_size: 20,
    type: navList.value[navCurrent.value].id
  }
  getMyCollectBranchList()
}

const navCurrent = ref(0)
const navList = ref([
  {
    name: '我申请的牵线',
    id: 0,
  },
  {
    name: '向我申请的牵线',
    id: 1,
  }
])

const navTo = (url: any) => {
  uni.navigateTo({ url })
}

let theUserInfo = reactive({})
const isShowMain = ref(false)
const getTheUserInfo = async () => {
  theUserInfo = await getUserInfoApi({})

  console.log('theUserInfo', theUserInfo);

  getMyCollectBranchList()
}


onShow(() => {
  getTheUserInfo()
})


let formData = ref({
  page_no: 1,
  page_size: 10,
  type: navList.value[navCurrent.value].id
}) as any

let MyCollectBranch = ref({
  lists: []
})

const getMyCollectBranchList = async () => {
  const data: any = await getMyQxListApi(formData.value)
  MyCollectBranch.value.lists.push(...data.lists)
  isShowMain.value = true
}

onReachBottom(() => {
  if (MyCollectBranch.value.lists.length < MyCollectBranch.value.count) {
    formData.value.page_no++
    getMyCollectBranchList()
  }
})
</script>

<style lang="scss" scoped>
.index {
  padding-bottom: 60rpx;
  position: relative;
  background-repeat: no-repeat;
  background-size: 100% auto;
  overflow: hidden;
  width: 100%;
  transition: all 1s;
  min-height: calc(100vh - env(safe-area-inset-bottom));
}


.page-card {
  width: calc(100% - 60rpx);
  margin: 0 auto;
  border-radius: 30rpx;
  padding: 30rpx;
  background: linear-gradient(45deg, #fab9fc 26%, #ff58cc 83%);
  box-shadow: inset 0px 4px 10px 0px rgba(255, 255, 255, 0.4);

  .card-user {
    display: flex;
    align-items: center;
    justify-content: space-between;

    .user-left {
      display: flex;
      align-items: center;
      justify-content: flex-start;

      .left-pic {
        flex-shrink: 0;
        width: 130rpx;
        height: 130rpx;
        border-radius: 50%;
        border: 2rpx;
        margin-right: 20rpx;
      }

      .left-data {
        font-size: 28rpx;
        color: #C0ADFA;

        .data-title {
          margin-bottom: 10rpx;
          font-size: 30rpx;
          color: #ffffff;
          font-weight: bold;
        }

        .data-time {
          font-size: 24rpx;
          color: #ffffff;
        }
      }
    }

    .user-right {
      flex-shrink: 0;
      display: flex;
      align-items: flex-end;
      justify-content: flex-end;
      color: #fff;
      font-size: 28rpx;

      .right-number {
        font-size: 60rpx;
        font-weight: bold;
        margin-bottom: -14rpx;
      }
    }
  }

  .card-bottom {
    margin-top: 30rpx;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20rpx;

    .bottom-btn {
      padding: 30rpx;
      background-color: #ffe9fb;
      border-radius: 30rpx;
      position: relative;

      .btn-title {
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 32rpx;
        color: #FF4DCA;
        font-weight: bold;

        .xbImg {
          position: absolute;
          top: 0;
          right: 0;
        }
      }

      .btn-tip {
        color: #FF4DCA;
        font-size: 24rpx;
        opacity: 0.8;
      }
    }
  }
}

.page-list {
  padding: 30rpx;
  background-color: #ffffff;
  border-radius: 30rpx;

  .list-child {
    &:first-child {
      .child-item {
        .item-time {
          &:after {
            height: 50%;
          }
        }
      }
    }

    .child-item {
      .item-time {
        padding-left: 30rpx;
        font-size: 28rpx;
        color: #999999;
        position: relative;
        z-index: 1;

        &:before {
          content: '';
          width: 16rpx;
          height: 16rpx;
          background-color: var(--color-primary);
          border-radius: 50%;
          position: absolute;
          left: 0;
          top: 50%;
          transform: translate(-50%, -50%);
          z-index: 1;
        }

        &:after {
          content: '';
          width: 2rpx;
          height: 100%;
          background-color: #D8D8D8;
          border-radius: 50%;
          position: absolute;
          left: 0;
          bottom: 0;
          transform: translate(-50%);
          z-index: 0;
        }
      }

      .item-box {
        padding-left: 30rpx;
        position: relative;
        z-index: 0;
        padding-top: 20rpx;
        padding-bottom: 30rpx;

        &:before {
          content: '';
          width: 2rpx;
          height: 100%;
          background-color: #D8D8D8;
          border-radius: 50%;
          position: absolute;
          left: 0;
          top: 50%;
          transform: translate(-50%, -50%);
        }

        .box-user {
          padding: 30rpx;
          background-color: #F3F8FE;
          display: flex;
          align-items: center;
          justify-content: space-between;
          border-radius: 20rpx;

          .user-pic {
            flex-shrink: 0;
            width: 80rpx;
            height: 80rpx;
            border-radius: 50%;
          }

          .user-data {
            width: 100%;
            margin-left: 20rpx;

            .data-name {
              display: flex;
              align-items: center;
              justify-content: flex-start;

              .name-text {
                font-size: 28rpx;
                color: #111111;
                font-weight: bold;
              }

              .name-sex {
                background-color: #669cff;
                width: 30rpx;
                height: 30rpx;
                border-radius: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                flex-shrink: 0;
                text-align: center;
                margin-left: 10rpx;
                margin-bottom: 10rpx;

                &Nv {
                  background-color: #FF668A;
                }

                .sex-icon {
                  display: inline-block;
                  margin-left: 2rpx;
                }
              }
            }

            .data-id {
              font-size: 24rpx;
              color: #999999;
            }
          }

          .user-btn {
            flex-shrink: 0;
            padding: 10rpx 20rpx;
            border-radius: 30rpx;
            border: 2rpx solid var(--color-primary);
            font-size: 28rpx;
            color: var(--color-primary);
          }
        }
      }
    }
  }
}
</style>
